using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using SS;
using SS.dir;
using System;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Windows.Forms;
namespace TVSGPP.sys
{
	public class alterData : Form
	{
		private Func objFun = new Func();
		private frmWaitting objW;
		private IContainer components = null;
		private Button btnAction;
		private Button btnClose;
		private Label label1;
		public alterData()
		{
			this.InitializeComponent();
		}
		private void showWatting()
		{
			this.objW = new frmWaitting();
			this.objW.ShowDialog();
			Thread.Sleep(40);
		}
		private void btnAction_Click(object sender, EventArgs e)
		{
			ThreadStart start = new ThreadStart(this.showWatting);
			Thread thread = new Thread(start);
			thread.Start();
			if (!thread.Join(150))
			{
				this.runScripFile("");
			}
			thread.Abort();
		}
		public void runScripFile(string scriptFile)
		{
			try
			{
				string fileName = Application.StartupPath + "\\updateScript.sql";
				FileInfo fileInfo = new FileInfo(fileName);
				string sqlCommand = fileInfo.OpenText().ReadToEnd();
				SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
				Server server = new Server(new ServerConnection(sqlConnection));
				server.ConnectionContext.ExecuteNonQuery(sqlCommand);
				base.Close();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(alterData));
			this.btnAction = new Button();
			this.btnClose = new Button();
			this.label1 = new Label();
			base.SuspendLayout();
			this.btnAction.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.btnAction.Cursor = Cursors.Hand;
			this.btnAction.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnAction.Location = new Point(95, 60);
			this.btnAction.Name = "btnAction";
			this.btnAction.Size = new Size(85, 28);
			this.btnAction.TabIndex = 0;
			this.btnAction.Text = "Bắt đầu";
			this.btnAction.UseVisualStyleBackColor = true;
			this.btnAction.Click += new EventHandler(this.btnAction_Click);
			this.btnClose.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.btnClose.Cursor = Cursors.Hand;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new Point(184, 60);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(85, 28);
			this.btnClose.TabIndex = 1;
			this.btnClose.Text = "Kết thúc";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.label1.BackColor = Color.FromArgb(255, 255, 192);
			this.label1.BorderStyle = BorderStyle.Fixed3D;
			this.label1.Font = new Font("Arial", 8.25f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.label1.Location = new Point(12, 14);
			this.label1.Name = "label1";
			this.label1.Size = new Size(340, 34);
			this.label1.TabIndex = 2;
			this.label1.Text = "THAY ĐỔI CẤU TRÚC CƠ SỞ DỮ LIỆU";
			this.label1.TextAlign = ContentAlignment.MiddleCenter;
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(364, 96);
			base.Controls.Add(this.label1);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.btnAction);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			this.MaximumSize = new Size(380, 130);
			this.MinimumSize = new Size(380, 130);
			base.Name = "alterData";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = " ..: Cập nhật Database";
			base.ResumeLayout(false);
		}
	}
}
